/*
 * @Author: biankai
 * @Date: 2021-04-19 18:47:04
 * @LastEditTime: 2021-11-05 11:34:00
 * @LastEditors: biankai
 * @FilePath: /gitee/devops_service/src/controllers/kubernetes/Namespace.controller.ts
 */
import { Controller, Inject, Get, Query, Post, Body, Delete, Param, Put } from '@nestjs/common';
import { ApiCreatedResponse, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { NamespaceDto } from 'src/dto/kubernetes.dto';
import * as kubernetes from '@kubernetes/client-node';
import { NamespaceService } from 'src/services/kubernetes/namespace.service';


@ApiTags('K8s-命名空间')
@Controller('kubernetes/namespace')
export class NamespaceController {
    constructor(@Inject(NamespaceService) private readonly namespaceService: NamespaceService) {
    }

    @ApiOperation({ summary: '获取所有的命名空间', description: '说明 : 调用此接口,可获得所有命名空间' })
    @ApiCreatedResponse({
        description: 'The record has been successfully created.',
        type: kubernetes.V1Namespace
    })
    @Get()
    async listK8sNamespace(@Query() query: any) {
        return await this.namespaceService.listK8sNamespace()
    }

    @ApiOperation({ summary: '获取单个命名空间详情', description: '说明 : 调用此接口,可获得单个命名空间详情' })
    @Get(':name')
    async singleK8sNamespace(@Param('name') name) {
        return await this.namespaceService.singleK8sNamespace(name)
    }

    @ApiOperation({ summary: '新增命名空间', description: '说明 : 调用此接口,可新增命名空间' })
    @Post()
    async createK8sNamespace(@Body() namespaceDto: NamespaceDto) {
        return await this.namespaceService.createK8sNamespace(namespaceDto)
    }

    @ApiOperation({ summary: '修改命名空间', description: '说明 : 调用此接口,可修改命名空间' })
    @Put(':name')
    async replaceK8sNamespace(@Param('name') name, @Body() namespaceDto: NamespaceDto) {
        return await this.namespaceService.replaceK8sNamespace(name, namespaceDto)
    }
    @ApiOperation({ summary: '删除命名空间', description: '说明 : 调用此接口,可删除命名空间' })
    @Delete(':name')
    async deleteK8sNamespace(@Param('name') name) {
        return await this.namespaceService.deleteK8sNamespace(name)
    }

}